package com.whu.waterworks.action;

import com.opensymphony.xwork2.ActionSupport;
import com.whu.waterworks.model.WaterUser;
import com.whu.waterworks.service.WaterWorksUserService;

public class AddUser extends ActionSupport{
	private static final long serialVersionUID = -6711903257135011766L;
	private String userName;
	private String userPassword;
	private String roleSelect;
	private String workingPlace;
	private WaterWorksUserService waterWorksUserService ;
	private String result="";
	private WaterUser waterUser = new WaterUser();
	
	@Override
	public String execute() throws Exception {
		
		if (waterWorksUserService.getUserByName(userName)!=null) {
			result = "hasUser";
		}
		else {
			
			waterUser.setUsername(userName);
			waterUser.setPassword(userPassword);
			waterUser.setPermission(roleSelect);
			waterUser.setType("1");
			waterUser.setArea(workingPlace);
			if (waterWorksUserService.addUser(waterUser)) {
				result=SUCCESS;
			}
			else {
				result=ERROR;
			}	
		}
		return SUCCESS;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getUserPassword() {
		return userPassword;
	}

	public void setUserPassword(String userPassword) {
		this.userPassword = userPassword;
	}

	public String getRoleSelect() {
		return roleSelect;
	}

	public void setRoleSelect(String roleSelect) {
		this.roleSelect = roleSelect;
	}

	public String getWorkingPlace() {
		return workingPlace;
	}

	public void setWorkingPlace(String workingPlace) {
		this.workingPlace = workingPlace;
	}

	public WaterWorksUserService getWaterWorksUserService() {
		return waterWorksUserService;
	}

	public void setWaterWorksUserService(WaterWorksUserService waterWorksUserService) {
		this.waterWorksUserService = waterWorksUserService;
	}

	public String getResult() {
		return result;
	}

	public void setResult(String result) {
		this.result = result;
	}

	public WaterUser getWaterUser() {
		return waterUser;
	}

	public void setWaterUser(WaterUser waterUser) {
		this.waterUser = waterUser;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}
}	
